package com.luozongyao.statistics.scheduledTask;

import com.luozongyao.statistics.service.StatisticService;
import com.luozongyao.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author luozongyao
 * @date 2021/11/14
 */
//定时任务
@Component
public class ScheduledTask {

    @Autowired
    private StatisticService statisticService;
    //每天凌晨3点执行任务
    @Scheduled(cron = "40 20 14 * * ?")
    public  void startTask() {

        //执行昨天的统计任务
        String yesterday = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        statisticService.statisticCount(yesterday);
    }
    
    

}
